package com.cangshi.service;

import com.cangshi.dao.*;
import com.cangshi.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Eoly on 2017/1/16.
 */
@Service("addressService")
public class AddressServiceImpl implements AddressService{

    @Autowired
    AddressMapper addressMapper;

    public List<Address> findAddressByUserId(Integer userId) {
        return addressMapper.selectByUserId(userId);
    }

    public Address findAddressByAddressId(Integer addressId) {
        return addressMapper.selectByPrimaryKey(addressId);
    }

    public int addAddress(Address address) {
        return addressMapper.insertSelective(address);
    }

    public int getIdFromLastAdd() {
        return addressMapper.selectLastId();
    }

    public int deleteAddressByAddressId(int addressId) {
        return addressMapper.deleteByPrimaryKey(addressId);
    }

    public int updateAddress(Address address) {
        return addressMapper.updateByPrimaryKeySelective(address);
    }
}
